﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace clock
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        ///为了调出控制台输入
        [DllImport("kernel32.dll")]
        public static extern Boolean AllocConsole();
        [DllImport("kernel32.dll")]
        public static extern Boolean FreeConsole();

        static void Main()
        {
            AllocConsole();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            FreeConsole();
        }
    }

    public class MyList<T>
    {
        private Node<T> head;
        private Node<T> tail;


        public MyList()
        {
            this.head = null;
            this.tail = null;
        }
        public Node<T> Head
        {
            get => head;
        }
        public void Add(T t)
        {
            Node<T> node = new Node<T>(t);
            if (tail == null)
            {
                head = tail = node;
            }
            else
            {
                tail.Next = node;
                tail = tail.Next;
            }
        }
        public void ForEach(Action<T> act)
        {
            Node<T> current = Head;
            Action<T> action = act;
            dynamic sum = 0, maxx = int.MinValue, minn = int.MaxValue;
            while (current != null)
            {
                if (current.Data >= maxx)
                {
                    maxx = current.Data;
                }
                if (current.Data <= minn)
                {
                    minn = current.Data;
                }
                act(current.Data);
                sum += current.Data;
                current = current.Next;
            }
            Console.WriteLine("最大值是{0},最小值是{1},总和为{2}", maxx, minn, sum);
        }
    }
    public class Node<T>
    {
        public Node<T> Next;
        public T Data;
        public Node(T t)
        {
            Next = null;
            Data = t;
        }
    }
}
